import { mapGetters } from 'vuex';
import { alertMessage, isValidateNull } from '@/utils/utils';
import { createOrEditPasswordApi } from './edit-system.service';
export default {
  name: 'create-role',
  components: {},
  directives: {},
  props: {
    selectData: {
      type: Object,
      default: () => { }
    }
  },
  data() {
    return {
      loading: false, // table loading
      title: '平台初始密码设置',
      showDialog: true, // 是否显示弹窗
      passwordType: 'password',
      editForm: {}, // 编辑用户表单
      editRules: {
        password: [{ required: true, trigger: "change", validator: isValidateNull }]
      } // 编辑表单验证规则
    }
  },
  computed: {
    ...mapGetters([
      'codesCheck'
    ])
  },
  created() {
    this.editForm = JSON.parse(JSON.stringify(this.selectData));
  },
  methods: {
    showPwd() {
      if (this.passwordType === 'password') {
        this.passwordType = ''
      } else {
        this.passwordType = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password.focus()
      })
    },
    // 创建或者编辑信息
    save() {
      // 表单验证
      this.$refs.dataForm.validate(valid => {
        if (valid) {
          createOrEditPasswordApi(this.editForm).then((res) => {
            alertMessage(res.message);
            this.showDialog = false;
            this.$emit('reload', true)
          }).catch(() => { }); // 关闭confirm框的回调，不处理的话会报一个js error
        }
      });
    },

    // 关闭dialog时需要告诉父组件隐藏弹窗
    closeDialog() {
      this.showDialog = false;
      this.$emit('close', true);
    }
  }
}
